package com.liu.eduService.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.liu.R;
import com.liu.eduService.entity.EduCourse;
import com.liu.eduService.entity.EduTeacher;
import com.liu.eduService.service.EduCourseService;
import com.liu.eduService.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * **************
 * 项目名称: testgulili <br/>
 * 文件名称:  <br/>
 * 文件描述: 查询前 8 条热门课程、4名名师。 <br/>
 * 文件创建：刘世锦 <br/>
 * 创建时间: 2022/1/17 <br/>
 *
 * @version v1.0 <br/>
 * @update [序号][日期YYYY-MM-DD][更改人姓名][变更描述]<br/>
 * *************
 */
@RestController
@RequestMapping("/eduService/indexFront")
@CrossOrigin
public class indexFrontController {

    @Autowired
    private EduTeacherService eduTeacherService;
    @Autowired
    private EduCourseService eduCourseService;

//    查询前 8 条热门课程、4名名师。
    @Cacheable(key = "'getIndexData'",value = "banner")
    @GetMapping("getIndexData")
    public R getIndexData(){

        // 获取热门课程
        List<EduCourse> courseList =  eduCourseService.getHostCourse();
        // 获取热门名师
        QueryWrapper<EduTeacher> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 4");
        List<EduTeacher> teacherList = eduTeacherService.list(wrapper);
        return R.ok().data("courseList",courseList).data("teacherList",teacherList);
    }

}
